package com.fzhucc.modules.lesson.repository;

import com.fzhucc.modules.lesson.domain.LessonLabel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://eladmin.vip
* @author yyg
* @date 2022-12-07
**/
public interface LessonLabelRepository extends JpaRepository<LessonLabel, Integer>, JpaSpecificationExecutor<LessonLabel> {
    @Query("SELECT a from LessonLabel as a where a.lessonId=:lesson_id and a.labelName=:labelName")
    List<LessonLabel> findByLabelIdWithLabelName(int lesson_id, String labelName);

    @Modifying
    @Query(nativeQuery = true, value = "DELETE FROM tb_lesson_label WHERE lesson_id=:lesson_id")
    void deleteByLessonId(int lesson_id);

    @Query("SELECT a from LessonLabel as a where a.lessonId=:lesson_id")
    List<LessonLabel> findByLessonId(int lesson_id);
}